package com.weetop.akly.presenter;

import android.app.Activity;
import android.text.TextUtils;

import com.weetop.akly.base.mvp.BaseModel;
import com.weetop.akly.base.mvp.BaseObserver;
import com.weetop.akly.base.mvp.BasePresenter;
import com.weetop.akly.bean.TrainBean;
import com.weetop.akly.bean.TrainResult;
import com.weetop.akly.bean.VoteBean;
import com.weetop.akly.view.TrainDetailView;

public class TrainDetailPresent extends BasePresenter<TrainDetailView> {
    public TrainDetailPresent(TrainDetailView baseView, Activity activity) {
        super(baseView, activity);
    }

    /**
     * 获取考核信息
     */
    public void getTrainInfo(String code) {
        if (TextUtils.isEmpty(code)) {
            return;
        }
        addDisposable(apiServer.getTrainInfo(code), new BaseObserver<BaseModel<TrainBean>>(baseView) {
            @Override
            public void onSuccess(BaseModel<TrainBean> o) {
                baseView.getTrainInfoSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }
    /**
     * 获取考核结果
     */
    public void getTrainResult(String code) {
        if (TextUtils.isEmpty(code)) {
            return;
        }
        addDisposable(apiServer.getTrainResult(code), new BaseObserver<BaseModel<TrainResult>>(baseView) {
            @Override
            public void onSuccess(BaseModel<TrainResult> o) {
                baseView.getTrainResultSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

    /**
     * 提交考试操作
     */
    public void doTrain(String code, String ids) {
        if (TextUtils.isEmpty(code) || TextUtils.isEmpty(ids)) {
            return;
        }
        addDisposable(apiServer.doTrain(code, ids), new BaseObserver<BaseModel<Boolean>>(baseView) {
            @Override
            public void onSuccess(BaseModel<Boolean> o) {
                baseView.doTrainSuccess(o);
            }

            @Override
            public void onError(String msg) {
                if (baseView != null) {
                    baseView.showError(msg);
                }
            }
        });
    }

}
